package io.renren.modules.weixin.controller;

import io.renren.common.annotation.SysLog;
import io.renren.common.utils.*;
import io.renren.common.validator.ValidatorUtils;
import io.renren.modules.sys.entity.SysConfigEntity;
import io.renren.modules.sys.service.SysConfigService;
import io.renren.modules.weixin.config.WXConfig;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;

/**
 * 系统参数信息
 * 
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2016年12月4日 下午6:55:53
 */
@RestController
@RequestMapping("/weixin")
public class WXController extends AbstractController {
	@Autowired
	private SysConfigService sysConfigService;

	@Value("${weixin.token}")
	private String token;

	@Autowired
	private WXConfig wxConfig;

	@Autowired
	RedisUtils redisUtils;
	/**
	 * 所有配置列表
	 */
	@RequestMapping("/test")
//	@RequiresPermissions("sys:config:list")
	public void list(HttpServletRequest req, HttpServletResponse resp){
		//查询列表数据
			try {
				System.out.println(wxConfig.getToken());
				redisUtils.set("token",wxConfig.getToken(),DateUtils.Time.HOUR*2);

				System.out.println(redisUtils.get("token"));
				PrintWriter pw = resp.getWriter();
				pw.write(token);
				pw.flush();
				pw.close();
			} catch (Exception e) {
				logger.error("绑定服务器异常", e);
			}
	}
//	protected boolean isLegal(HttpServletRequest request) {
//		String signature = request.getParameter("signature");
//		String timestamp = request.getParameter("timestamp");
//		String nonce = request.getParameter("nonce");
//		return SignUtil.checkSignature("sdaldkkosdfoasdjklasd", signature, timestamp, nonce);
//	}

}
